package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.Enum.ResultEnum;
import com.dongdongshop.core.SpecificPrint;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerServiceI;
import com.dongdongshop.util.ShiroUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("tbSellerController")
public class TbSellerController {

    @Reference
    private TbSellerServiceI tbSellerServiceI;

    private Logger logger= LoggerFactory.getLogger(TbSellerController.class);

    @RequestMapping("saveTbSellerController")
    @ResponseBody
    public SpecificPrint saveTbSeller(TbSeller tbSeller){
        try {
            //set盐
            String salt = ShiroUtils.generateSalt(6);
            tbSeller.setSalt(salt);
            String password = ShiroUtils.encryptPassword("MD5",tbSeller.getPassword(),tbSeller.getSalt(),10);
            tbSeller.setPassword(password);
            tbSellerServiceI.saveTbSeller(tbSeller);

            logger.info(ResultEnum.SUCCESS.getMessage()+"，参数为：{}",tbSeller);
            return SpecificPrint.response(ResultEnum.SUCCESS).setData(tbSeller);
        }catch (Exception e){
            logger.error(ResultEnum.ERROR.getMessage(),e);
            return SpecificPrint.response(ResultEnum.ERROR);
        }
    }
}
